﻿using System;
using System.Data.SqlClient;
using System.Web.UI;

namespace 基本ADO.NET对象
{
    public partial class DataReader对象 : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            const string connectionString = "data source=127.0.0.2;database=NorthwindCHS;uid=sa;pwd=liuxiaozeng";

            using (var sqlConnection = new SqlConnection(connectionString))
            {
                try
                {
                    sqlConnection.Open();
                    var sqlCommand = new SqlCommand("SELECT 产品名称 FROM 产品", sqlConnection); //也可以分步骤做

                    SqlDataReader dataReader = sqlCommand.ExecuteReader();
                    while (dataReader.Read())
                    {
                        Response.Write(dataReader["产品名称"] + "<br/>");
                    }
                }
                catch (Exception exception)
                {
                    throw new Exception(exception.Message);
                }
            }
        }
    }
}